package ysq.xyg.gaodeapi;


import com.alibaba.fastjson.JSONObject;
import ysq.xyg.base.util.httpClient.HttpUtil;
import ysq.xyg.wxapi.model.base.HttpMethod;

/**
 * 高德api接口
 *
 */

public class GaoDeApi {

private static String key="293a5be6691f901bdd7bc0b5cfe986e7";
    /**
     * 根据经纬度获取所在县
     *
     **/
    public static String acceptAddress(String location) throws Exception {
        //传入的参数
        String url = "https://restapi.amap.com/v3/geocode/regeo?output=JSON&location="+location+"&key="+key;

        JSONObject jsonObject = HttpUtil.httpRequestAndReturnResult(url, HttpMethod.GET, "");
        String status=jsonObject.getString("status");
        if("1".equals(status)){
            JSONObject jsonOne=jsonObject.getJSONObject("regeocode");
            if(jsonOne==null){
                return "";
            }
            JSONObject addressComponentJson=jsonOne.getJSONObject("addressComponent");
            if(addressComponentJson==null){
                return "";
            }
            String district=addressComponentJson.getString("district");
            return district;
        }

        return "";
    }


}
